package com.huluobo.a2207douyindemo.live;

import androidx.lifecycle.MutableLiveData;

import com.huluobo.base.bean.CommonBeanResult;
import com.huluobo.base.bean.GiftBeanResult;
import com.huluobo.base.mvvm.BaseRepo;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.RequestBody;

/**
 * Created by LC on 2024/9/23.
 */
public class LiveRepo extends BaseRepo {
    public void followAuth(RequestBody body, MutableLiveData<CommonBeanResult> success,
                           MutableLiveData<String> failed) {
        apiService.followAuth(body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<CommonBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(CommonBeanResult commonBeanResult) {
                        success.setValue(commonBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void cancelFollow(RequestBody body, MutableLiveData<CommonBeanResult> success,
                             MutableLiveData<String> failed) {
        apiService.cancelFollow(body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<CommonBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(CommonBeanResult commonBeanResult) {
                        success.setValue(commonBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getGift(MutableLiveData<GiftBeanResult> success, MutableLiveData<String> failed) {
        apiService.getGift()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<GiftBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(GiftBeanResult giftBeanResult) {
                        success.setValue(giftBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
